package com.lcy.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcy.reggie.common.Result;
import com.lcy.reggie.entity.Employee;
import com.lcy.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * ======刘春春大帅逼======
 * ******java学习之旅******
 */

@Slf4j
@RequestMapping("/employee")
@RestController
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<Employee> login(HttpServletRequest request, @RequestBody Employee employee){
       return employeeService.login(request,employee);
    }

    /**
     * 用户退出
     */
    @PostMapping("/logout")
    public Result<String> logout(HttpServletRequest request){
        request.getSession().removeAttribute("employee");
        return Result.success("成功退出！");
    }

    /**
     *  添加员工信息
     */
    @PostMapping
    public Result<String> save(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.saveEmployee(request,employee);
    }

    /**
     *  分页功能
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public Result<Page> page(HttpServletRequest request,Integer page,Integer pageSize,String name){
        return employeeService.page(request,page,pageSize,name);
    }


    /**
     *  禁用功能
     * @param request
     * @param employee
     * @return
     */
    @PutMapping
    public Result<String> update(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.update(request,employee);
    }

    /**
     * 回显功能
     */
    @GetMapping("/{id}")
    public Result<Employee> query(@PathVariable Long id){
        Employee employee = employeeService.getById(id);
        return Result.success(employee);
    }

}
